//
//  API_Multithreading_Actor_Demo1VC.swift
//  APSwift
//
//  Created by jianbo.pei on 2023/7/24.
//  

import UIKit

class API_Multithreading_Actor_Demo1VC: UIViewController {

    override func viewDidLoad() {
        super.viewDidLoad()

        // Do any additional setup after loading the view.

        let feeder = ChickenFeeder()
        Task {
            await feeder.chickenStartsEating()
            print(await feeder.numberOfEatingChickens) // Prints: 1
        }
    }

}

actor ChickenFeeder {
    let food = "worms"
    var numberOfEatingChickens: Int = 0
    
    func chickenStartsEating() {
        numberOfEatingChickens += 1
    }
    
    func chickenStopsEating() {
        numberOfEatingChickens -= 1
    }
}
